package com.yuliang.ai.service.Impl;

import com.alibaba.fastjson.JSONArray;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yuliang.ai.domain.Dto.HumanPicInfoDto;
import com.yuliang.ai.domain.Vo.HumanPicInfoVo;
import com.yuliang.ai.domain.entity.HumanPicInfo;
import com.yuliang.ai.mapper.HumanPicInfoMapper;
import com.yuliang.ai.service.HumanPicInfoService;
import com.yuliang.utils.result.ResultUtils;
import com.yuliang.utils.result.emums.HttpCodeEnum;
import com.yuliang.utils.superbackage.SuperServiceImpl;
import com.yuliang.utils.util.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author Huangkai
 */
@Slf4j
@Service
public class HumanPicInfoServiceImpl extends SuperServiceImpl<HumanPicInfoMapper, HumanPicInfo> implements HumanPicInfoService {

    @Autowired
    HumanPicInfoService humanPicInfoService;

    @Override
    public String insertHumanPicInfo(HumanPicInfoVo humanPicInfoVo) {
        HumanPicInfo humanPicInfo = new HumanPicInfo();
        humanPicInfo.setUuid(StringUtils.getSnowFlakeId());
        humanPicInfo.setHumanIdentifyId(humanPicInfoVo.getHumanIdentifyId());
        humanPicInfo.setPicLength(humanPicInfoVo.getPicLength());
        humanPicInfo.setPicWidth(humanPicInfoVo.getPicWidth());
        humanPicInfo.setHumanPic(humanPicInfoVo.getHumanPic());
        humanPicInfo.setType(humanPicInfoVo.getType());
        humanPicInfo.insert();
        return ResultUtils.ResultWithMessageEnum(HttpCodeEnum.insert_success);
    }

    @Override
    public List<HumanPicInfoDto> selectHumanPicInfoList(HumanPicInfoVo humanPicInfoVo) {
        LambdaQueryWrapper<HumanPicInfo> wrapper = new QueryWrapper<HumanPicInfo>().lambda();
        wrapper.eq(HumanPicInfo::getHumanIdentifyId, humanPicInfoVo.getHumanIdentifyId());
        List<HumanPicInfo> humanPicInfoList = humanPicInfoService.list(wrapper);
        if(humanPicInfoList != null && humanPicInfoList.size() > 0){
            String jsonArrayStr = JSONArray.toJSONString(humanPicInfoList);
            List<HumanPicInfoDto>  humanPicInfoDtoList = JSONArray.parseArray(jsonArrayStr, HumanPicInfoDto.class);
            return humanPicInfoDtoList;
        }
        return null;
    }
}
